package se.recept.kollen.model;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author jocke
 */
@Entity
@Table(name = "Ingredient")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = Ingredient.FIND_ALL, query = "SELECT i FROM Ingredient i"),
    @NamedQuery(name = "Ingredient.findById", query = "SELECT i FROM Ingredient i WHERE i.id = :id"),
    @NamedQuery(name = "Ingredient.findByStatus", query = "SELECT i FROM Ingredient i WHERE i.status = :status"),
    @NamedQuery(name = "Ingredient.findByPlu", query = "SELECT i FROM Ingredient i WHERE i.plu = :plu"),
    @NamedQuery(name = "Ingredient.findByCreated", query = "SELECT i FROM Ingredient i WHERE i.created = :created"),
    @NamedQuery(name = Ingredient.FIND_BY_LIKE_NAME , query = "SELECT i FROM Ingredient i WHERE i.name LIKE :name"),
    @NamedQuery(name = Ingredient.FIND_BY_ACTIVE, query = "SELECT i FROM Ingredient i WHERE i.active = :active"),
    @NamedQuery(name = "Ingredient.findByModified", query = "SELECT i FROM Ingredient i WHERE i.modified = :modified")})
public class Ingredient implements Serializable {
    private static final long serialVersionUID = 1L;
    
    public static final String FIND_ALL = "Ingredient.findAll";
    public static final String FIND_BY_ACTIVE = "Ingredient.findByActive";
    public static final String FIND_BY_LIKE_NAME = "Ingredient.likeName";
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID")
    private Integer id;
    
    @Basic(optional = false)
    @Column(name = "NAME")
    private String name;
    
    @Basic(optional = false)
    @NotNull
    @Column(name = "STATUS")
    private short status;
    
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "PLU")
    private String plu;
    
    @Basic(optional = false)
    @NotNull
    @Column(name = "CREATED")
    @Temporal(TemporalType.TIMESTAMP)
    private Date created;
    
    @Basic(optional = false)
    @NotNull
    @Column(name = "ACTIVE")
    private boolean active;
    
    @Basic(optional = false)
    @NotNull
    @Column(name = "MODIFIED")
    @Temporal(TemporalType.TIMESTAMP)
    private Date modified;
    
    @JoinColumn(name = "CATEGORY_ID", referencedColumnName = "ID")
    @ManyToOne(optional = false)
    private IngredientCategory category;

    public Ingredient() {
    }

    public Ingredient(Integer id) {
        this.id = id;
    }

    public Ingredient(Integer id, short status, String plu, Date created, boolean active, Date modified) {
        this.id = id;
        this.status = status;
        this.plu = plu;
        this.created = created;
        this.active = active;
        this.modified = modified;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public short getStatus() {
        return status;
    }

    public void setStatus(short status) {
        this.status = status;
    }

    public String getPlu() {
        return plu;
    }

    public void setPlu(String plu) {
        this.plu = plu;
    }

    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public boolean getActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public Date getModified() {
        return modified;
    }

    public void setModified(Date modified) {
        this.modified = modified;
    }

    public IngredientCategory getCategory() {
        return category;
    }

    public void setCategory(IngredientCategory category) {
        this.category = category;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Ingredient)) {
            return false;
        }
        Ingredient other = (Ingredient) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "se.recept.kollen.model.Ingredient[ id=" + id + " ]";
    }
    
}
